#include <iostream>

using namespace std;
int lengthOfLongestSubstring(string s) {
    int record[256];//保存字符上一次出现的位置
    memset(record, -1, sizeof(record));
    int idx = -1, max = 0;
    for (int i = 0; i < s.size(); i++) {
        if (record[s[i]] > idx) {
            idx = record[s[i]];
        }

        if (i - idx > max) {
            max = i - idx;
        }

        record[s[i]] = i;
    }
    return max;
}
int main() {
    string s = "pwwkew";
    cout << lengthOfLongestSubstring(s);
}